home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 16 / checksum.fth < prev    next >
Text File  |  1985-11-19  |  768b  |  24 lines

  1. \ Finds the checksum of a file.  The checksum is computed by accumulating
  2. \ bytes into a 16-bit (at least) word, and printing the least-significant
  3. \ 16 bits of the result in both hex and decimal .
  4. \
  5. \ checsksum filename        Print the checksum of the file
  6.  
  7. variable accum
  8. : checksum  \ filename ( -- )
  9.    accum off
  10.    reading
  11.    begin  ifd @ fgetc  dup 0>=   while  accum +!  repeat
  12.    ifd @ close
  13.    base @
  14.       accum @  th ffff  and
  15.       dup hex 6 u.r  ."  (hex)   "
  16.       decimal 6 u.r  ."  (decimal)"
  17.    base !
  18.    cr
  19. ;
  20. ecimal
  21. : append-file ( -- )
  22.    begin
  23.         pad  4096  ifd @   fgets  ( #bytes-read)
  24.         d